home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / utils / mailstat / mailstat.c next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  2.5 KB  |  120 lines

  1. #include <exec/types.h>
  2. #include <exec/exec.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "dh0:code/code20/defines.h"
  6.  
  7. struct MailStat MS;
  8. char conf[200];
  9. BOOL UPDATE=FALSE;
  10. void NullStats();
  11. int TLock(char *str);
  12. void sr(char *str);
  13. char temp[200];
  14. main(int argc,char *argv[])
  15. {
  16.   FILE *fi;
  17.   if(argc<2 || argc >3)
  18.   {
  19.     printf("MailStats version 1.0 written by Joseph Hodge\n");
  20.     printf("Usage: MailStats <conference path> [UPDATE]\n");
  21.     printf("   ie: MailStats BBS:PD\n");
  22.     printf("\n\n");
  23.     printf("This is an AmiExpress 1.1w+ utility\n");
  24.     printf("\n");
  25.     exit(0);
  26.   }
  27.   
  28.   strcpy(conf,argv[1]);
  29.   sr(conf);
  30.   if(!TLock(conf))
  31.   {
  32.      printf("Can't locate conference location %s\n",conf);
  33.      printf("\n");
  34.      exit(0);
  35.   }
  36.   if(argc==3)
  37.   {
  38.     UPDATE=TRUE;
  39.   }
  40.   strcat(conf,"/MsgBase/MailStats");
  41.   NullStats();
  42.   if(TLock(conf))
  43.   {
  44.     fi=fopen(conf,"rb");
  45.     if(fi==NULL)
  46.     {
  47.       printf("Error! can't open file %s\n",conf);
  48.       exit(0);
  49.     }
  50.     fread((APTR)&MS,sizeof(struct MailStat),1,fi);
  51.     fclose(fi);
  52.     printf("Current MailStats\n");
  53.     printf("\n");
  54.     printf("LowestKey    :%ld\n",MS.LowestKey);
  55.     printf("HighMsgNum   :%ld\n",MS.HighMsgNum);
  56.     printf("LowestNotDel :%ld\n",MS.LowestNotDel);
  57.     printf("\n\n");
  58.   }
  59.   else
  60.   {
  61.     if(!UPDATE)
  62.     {
  63.       printf("Error!, MailStats does not exist for this conference\n");
  64.       printf("This is normal if the message base has not been used\n");
  65.       printf("But if the message base has been used then please run\n");
  66.       printf("this utility with the UPDATE option\n");
  67.       printf("\n\n");
  68.       exit(0);
  69.     }
  70.   }
  71.   if(UPDATE)
  72.   {
  73.     printf("Enter New LowestKey    >:");
  74.     gets(temp);
  75.     MS.LowestKey=atol(temp);
  76.     printf("Enter New HighMsgNum   >:");
  77.     gets(temp);
  78.     MS.HighMsgNum=atol(temp);
  79.     printf("Enter New LowestNotDel >:");
  80.     gets(temp);
  81.     MS.LowestNotDel=atol(temp);
  82.     fi=fopen(conf,"wb");
  83.     if(fi==NULL)
  84.     {
  85.       printf("Error!, can't create MailStats file\n");
  86.       printf("\n\n");
  87.       exit(0);
  88.     }
  89.     fwrite((APTR)&MS,sizeof(struct MailStat),1,fi);
  90.     fclose(fi);
  91.   }
  92.   
  93. }
  94. void sr(char *str)
  95. {
  96.   register int i;
  97.   i=strlen(str)-1;
  98.   while(i>-1)
  99.   {
  100.     if(*(str+i)<=32) *(str+i)='\0'; else break;
  101.     i--; 
  102.   }
  103. }
  104. #define ACCESS_READ -2
  105. int TLock(char *str)
  106. {
  107.   long lock;
  108.   if(lock=Lock(str,ACCESS_READ))
  109.   {
  110.     UnLock(lock); return(1);
  111.   }
  112.   return(0);
  113. }
  114. void NullStats()
  115. {
  116.   MS.LowestKey=0L;
  117.   MS.HighMsgNum=0L;
  118.   MS.LowestNotDel=0L;
  119.   strcpy(MS.Pad,"     ");
  120. }